package thread.blockingQueue;

public class TestBlockingQueue {
    //生产者-消费者模型
    public static void main(String[] args) {
        MyBlockingQueue queue = new MyBlockingQueue();

        Thread t1 = new Thread(() -> {
            while(true) {
                try {
                    String result = queue.take();
                    System.out.println("消费：" + result);
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        Thread t2 = new Thread(() -> {
            //生产者
            int num = 0;
            while(true) {
                try {
                    queue.put(num + "");
                    System.out.println("生产：" + num);
                    num++;
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        t1.start();
        t2.start();
    }
}
